<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="${pageContext.request.contextPath}/jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/jquery-1.11.1-min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
<style>
	#sp{
		color: red;
		font-size: 12px;
	}
</style>
	<script type="text/javascript">
	$(function () {
		/*给浏览器窗口添加 回车事件*/
		$(window).keydown(function (e) {
			//如果按的是回车键  则提交登录请求
			if(e.keyCode == 13){
				$("#loginBtn").click();//模拟一次点击事件
			}
		});
		/*登录 点击事件*/
		$("#loginBtn").click(function () {
			//收集参数
			var loginAct=$.trim($("#loginAct").val());
			var loginPwd=$.trim($("#loginPwd").val());
			var isRemPwd=$("#isRemPwd").prop("checked");
			//表单验证
			if(loginAct==""){
				$("#sp").html("用户名不能为空")
				return;
			}
			if(loginPwd==""){
				$("#sp").html("密码不能为空")
				return;
			}
			$.ajax({
				url:"${pageContext.request.contextPath}/settings/login",
				data:{
					loginAct:loginAct,
					loginPwd:loginPwd,
					isRemPwd:isRemPwd
				},
				type:"post",
				dataType:"json",
				success:function (data) {
					if(data.code=="0"){//登录失败 提示错误信息
						$("#sp").html(data.msg)
					} else {
						/*跳转到首页  登录成功*/
						window.location.href="${pageContext.request.contextPath}/global/index"
					}
				}
			})
		})
	});
</script>
</head>
<body>
	<div style="position: absolute; top: 0px; left: 0px; width: 60%;">
		<img src="${pageContext.request.contextPath}/image/IMG_7114.JPG" style="width: 100%; height: 90%; position: relative; top: 50px;">
	</div>
	<div id="top" style="height: 50px; background-color: #3C3C3C; width: 100%;">
		<div style="position: absolute; top: 5px; left: 0px; font-size: 30px; font-weight: 400; color: white; font-family: 'times new roman'">CRM管理系统 &nbsp;<span style="font-size: 12px;">&copy;2022&nbsp;XYP</span></div>
	</div>
	
	<div style="position: absolute; top: 120px; right: 100px;width:450px;height:400px;border:1px solid #D5D5D5">
		<div style="position: absolute; top: 0px; right: 60px;">
			<div class="page-header">
				<h1>登录</h1><span id="sp"></span>
			</div>
			<form action="${pageContext.request.contextPath}/workbench/index.html" class="form-horizontal" role="form">
				<div class="form-group form-group-lg">
					<div style="width: 350px;">
						<input class="form-control" id="loginAct" type="text" placeholder="用户名" value="${cookie.loginAct.value}"  name="loginAct">
					</div>
					<div style="width: 350px; position: relative;top: 20px;">
						<input class="form-control" type="password" id="loginPwd" placeholder="密码" value="${cookie.loginPwd.value}" name="loginPwd">
					</div>
					<div class="checkbox" name="isRemPwd" style="position: relative;top: 30px; left: 10px;">
						<label>
							<c:if test="${not empty cookie.loginAct and not empty cookie.loginPwd}">
								<%--如果cookie中不为空 则默认勾选上--%>
								<input type="checkbox" checked="checked"  id="isRemPwd">
							</c:if>
							<c:if test="${ empty cookie.loginAct  or  empty cookie.loginPwd}">
								<%--如果cookie中为空 则不勾选上--%>
								<input type="checkbox"  id="isRemPwd">
							</c:if>
							十天内免登录
						</label>
					</div>
					<button type="button" id="loginBtn" class="btn btn-primary btn-lg btn-block"  style="width: 350px; position: relative;top: 45px;">登录</button>
				</div>
			</form>
		</div>
	</div>
</body>
</html>